package com.hxzy.shop.marketing.controller;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.common.dto.marketing.req.*;
import com.hxzy.shop.common.dto.marketing.resp.DistributionDrugResp;
import com.hxzy.shop.entity.DistributionLevel;
import com.hxzy.shop.marketing.dto.resp.DistributionDrugListResp;
import com.hxzy.shop.marketing.dto.resp.DistributionGlobalAndBindRuleResp;
import com.hxzy.shop.marketing.service.DistributionDrugService;
import com.hxzy.shop.marketing.service.DistributionGlobalRuleService;
import com.hxzy.shop.marketing.service.DistributionLevelService;
import com.hxzy.shop.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @ Author     ：dididi
 * @ Date       ：Created in 14:50 2023/8/2
 * @ Modified By：
 */
@Api(tags = "分销")
@RestController
@RequestMapping(value = "/distribution")
public class DistributionController {

    @Resource
    private DistributionLevelService distributionLevelService;

    @Resource
    private DistributionGlobalRuleService distributionGlobalRuleService;

    @Autowired
    private DistributionDrugService distributionDrugService;



    @ApiOperation(value = "分销等级列表")
    @PostMapping(value = "/levelList")
    public Result<List<DistributionLevel>> levelList(){
        return Result.success(distributionLevelService.levelList());
    }

    @ApiOperation(value = "全球分销规则")
    @PostMapping(value = "/globalRule")
    Result<DistributionGlobalAndBindRuleResp> globalRule(){
        return Result.success(distributionGlobalRuleService.selectGlobalRule());
    }

    @ApiOperation(value = "编辑分销等级")
    @PostMapping(value = "/levelSave")
    Result<Object> levelSave(@RequestBody List<DistributionLevelSaveReq> reqs){
        return Result.success(this.distributionLevelService.levelSave(reqs));
    }

    @PostMapping(value = "/globalRule/update")
    @ApiOperation(value = "编辑分销全局规则")
    public Result<Object> globalRuleUpdate(@RequestBody DistributionGlobalRuleUpdateReq req){
       return Result.success(this.distributionGlobalRuleService.globalRuleUpdate(req));
    }

    @PostMapping(value = "/drugList")
    @ApiOperation(value = "分销药品列表")
    Result<PageInfo<DistributionDrugListResp>> drugList(@RequestBody DistributionDrugPageReq req){
        return Result.success(this.distributionDrugService.drugList(req));
    }
    @PostMapping(value = "/noSelect/drugList")
    @ApiOperation(value = "分销未选药品列表")
    Result<PageInfo<DistributionDrugResp>> noSelectdrugList(@RequestBody DistributionDrugNoSelectReq req){
        return Result.success(this.distributionDrugService.noSelectdrugList(req));
    }

    @PostMapping(value = "/drug/update")
    @ApiOperation(value = "修改分销药品")
    Result<Object> updateDistributionDrug(@RequestBody @Validated UpdateDistributionDrugReq req){
        return Result.success(this.distributionDrugService.updateDistributionDrug(req));
    }

    @PostMapping(value = "/drug/add")
    @ApiOperation(value = "添加分销药品")
    Result<Object> addDistributionDrug(@RequestBody AddDistributionDrugReq req){
        return Result.success(this.distributionDrugService.addDistributionDrug(req));
    }

    @PostMapping(value = "/distribution/drug/delete")
    @ApiOperation(value = "删除分销药品")
    Result<Object> deleteDistributionDrug(@RequestBody @NotNull DeleteDistributionDrugReq req){
        return Result.success(this.distributionDrugService.deleteDistributionDrug(req));
    }
}
